<!--
 * @Description: 生产任务单
 * 
 * @Author: Edan<Edan>
 * @Date: 2024-07-19 09:49:19
 * @FilePath: /yuxiuproweb/src/views/qb/qb/mods/add.vue
-->

<template>
  <el-dialog
    :close-on-click-modal="false"
    :title="title"
    :visible.sync="shows"
    width="82vw"
    append-to-body
  >
    <selOrder ref="selOrder" :multi="1" :state="4" :orderType="'YC'" />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="shows = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { toTaskOrder } from "@/api/qb";
import selOrder from "@/views/qb/order/components/select.vue";
export default {
  components: { selOrder },
  props: {
    show: Boolean,
    type: {
      type: String,
      default: "add",
    },
    data: {
      type: Object,
    },
  },
  data() {
    return {
      // 表单参数
    };
  },
  computed: {
    title() {
      return {
        add: "添加任务单",
        edit: "修改任务单",
      }[this.type];
    },
    shows: {
      get() {
        return this.show;
      },
      set(newValue) {
        this.$emit("update:show", newValue);
      },
    },
  },
  async mounted() {
    // if (this.type === "edit") {
    //   this.handleUpdate();
    // }
    this.$nextTick(() => {
      this.$refs.selOrder.getList();
    });
  },
  methods: {
    /** 提交按钮 */
    submitForm() {
      const selListVal = this.$refs.selOrder.$refs.selectVal.selection;
      if (!selListVal.length) {
        // this.$mount
        this.$message.error("请选择要添加的单据！！");
        return;
      }
      var paramArr = [];
      for (var i = 0; i < selListVal.length; i++) {
        var item = selListVal[i];
        paramArr.push(item);
      }
      console.log(paramArr);
      toTaskOrder(paramArr).then((res) => {
        this.$modal.msgSuccess(res.msg || "添加成功");
        this.shows = false;
        this.$emit("update");
      });
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep {
  .el-form-item {
    input {
      text-align: left;
    }
  }
}
.open-right {
  ::v-deep {
    .el-form-item {
      margin-bottom: 0;
    }
  }
}
</style>
